home *** CD-ROM | disk | FTP | other *** search
/ Programming Languages Suite / ProgramD2.iso / Borland / Borland C++ V5.02 / EDITSDI.PAK / ABOUT.C next >
C/C++ Source or Header  |  1997-05-06  |  8KB  |  288 lines

  1. // THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
  2. // ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
  3. // THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
  4. // PARTICULAR PURPOSE.
  5. //
  6. // Copyright (C) 1993 - 1995  Microsoft Corporation.  All Rights Reserved.
  7. //
  8. //  MODULE:   about.c
  9. //
  10. //  PURPOSE:   Displays the "About" dialog box
  11. //
  12. //  FUNCTIONS:
  13. //    CmdAbout        - Displays the "About" dialog box
  14. //    About           - Processes messages for "About" dialog box.
  15. //    MsgAboutInit    - To initialize the about box with version info
  16. //                      from resources.
  17. //    MsgAboutCommand - Process WM_COMMAND message sent to the about box.
  18. //    CmdAboutDone    - Free the about box and related data.
  19. //
  20. //  COMMENTS:
  21. //
  22. //
  23.  
  24. #include <windows.h>            // required for all Windows applications
  25. #include <windowsx.h>
  26.  
  27. #ifdef WIN16
  28. #include "win16ext.h"           // required only for win16 applications
  29. #endif
  30. #include "globals.h"            // prototypes specific to this application
  31. #include "resource.h"
  32.  
  33.  
  34. #ifdef WIN16
  35. // Dialog box procedures must be exported in 16-bit applications for Windows.
  36. LRESULT CALLBACK __export About(HWND, UINT, WPARAM, LPARAM);
  37. #else
  38. LRESULT CALLBACK About(HWND, UINT, WPARAM, LPARAM);
  39. #endif
  40.  
  41. LRESULT MsgAboutInit(HWND, UINT, WPARAM, LPARAM);
  42. LRESULT MsgAboutCommand(HWND, UINT, WPARAM, LPARAM);
  43. LRESULT CmdAboutDone(HWND, WORD, WORD, HWND);
  44.  
  45. // About dialog message table definition.
  46. MSD rgmsdAbout[] =
  47. {
  48.     {WM_COMMAND,    MsgAboutCommand},
  49.     {WM_INITDIALOG, MsgAboutInit}
  50. };
  51.  
  52. MSDI msdiAbout =
  53. {
  54.     sizeof(rgmsdAbout) / sizeof(MSD),
  55.     rgmsdAbout,
  56.     edwpNone
  57. };
  58.  
  59. // About dialog command table definition.
  60. CMD rgcmdAbout[] =
  61. {
  62.     {IDOK,     CmdAboutDone},
  63.     {IDCANCEL, CmdAboutDone}
  64. };
  65.  
  66. CMDI cmdiAbout =
  67. {
  68.     sizeof(rgcmdAbout) / sizeof(CMD),
  69.     rgcmdAbout,
  70.     edwpNone
  71. };
  72.  
  73. // Module specific "globals"  Used when a variable needs to be
  74. // accessed in more than on handler function.
  75.  
  76. HFONT hFontCopyright;
  77.  
  78. //
  79. //  FUNCTION: CmdAbout(HWND, WORD, WORD, HWND)
  80. //
  81. //  PURPOSE: Displays the "About" dialog box
  82. //
  83. //  PARAMETERS:
  84. //    hwnd      - Window handle
  85. //    wCommand  - IDM_ABOUT (unused)
  86. //    wNotify   - Notification number (unused)
  87. //    hwndCtrl  - NULL (unused)
  88. //
  89. //  RETURN VALUE:
  90. //
  91. //    Always returns 0 - Message handled
  92. //
  93. //  COMMENTS:
  94. //    To process the IDM_ABOUT message, call DialogBox() to display the
  95. //    about dialog box.
  96.  
  97. #pragma argsused
  98. LRESULT CmdAbout(HWND hwnd, WORD wCommand, WORD wNotify, HWND hwndCtrl)
  99. {
  100.     DialogBox(hInst, "AboutBox", hwnd, (DLGPROC)About);
  101.     return 0;
  102. }
  103.  
  104.  
  105. //
  106. //  FUNCTION: About(HWND, UINT, WPARAM, LPARAM)
  107. //
  108. //  PURPOSE:  Processes messages for "About" dialog box.
  109. //
  110. //  PARAMETERS:
  111. //    hdlg - window handle of the dialog box
  112. //    wMessage - type of message
  113. //    wparam - message-specific information
  114. //    lparam - message-specific information
  115. //
  116. //  RETURN VALUE:
  117. //    TRUE - message handled
  118. //    FALSE - message not handled
  119. //
  120. //  COMMENTS:
  121. //
  122. //     Display version information from the version section of the
  123. //     application resource.
  124. //
  125. //     Wait for user to click on "Ok" button, then close the dialog box.
  126. //
  127.  
  128. LRESULT CALLBACK About(HWND hdlg, UINT uMessage, WPARAM wparam, LPARAM lparam)
  129. {
  130.     return DispMessage(&msdiAbout, hdlg, uMessage, wparam, lparam);
  131. }
  132.  
  133.  
  134. //
  135. //  FUNCTION: MsgAboutInit(HWND, UINT, WPARAM, LPARAM)
  136. //
  137. //  PURPOSE: To initialize the about box with version info from resources.
  138. //
  139. //  PARAMETERS:
  140. //    hwnd - The window handing the message.
  141. //    uMessage - The message number. (unused).
  142. //    wparam - Message specific data (unused).
  143. //    lparam - Message specific data (unused).
  144. //
  145. //  RETURN VALUE:
  146. //    Always returns 0 - message handled.
  147. //
  148. //  COMMENTS:
  149. //    Uses the version apis to retrieve version information for
  150. //    each of the static text boxes in the about box.
  151. //
  152.  
  153. #pragma argsused
  154. LRESULT MsgAboutInit(HWND hdlg, UINT uMessage, WPARAM wparam, LPARAM lparam)
  155. {
  156.     #define POINTSIZE 8
  157.  
  158.     char  szFullPath[256];
  159.     DWORD dwVerHnd;
  160.     DWORD dwVerInfoSize;
  161.     HDC   hDC;
  162.     int   iLogPixelsY, iPointSize;
  163.  
  164.     // Center the dialog over the application window
  165.     CenterWindow(hdlg, GetWindow(hdlg, GW_OWNER));
  166.  
  167.     // Set the copyright font to something smaller than default
  168.     hDC = GetDC(hdlg);
  169.     iLogPixelsY = GetDeviceCaps(hDC, LOGPIXELSY);
  170.     ReleaseDC(hdlg, hDC);
  171.     iPointSize = MulDiv(iLogPixelsY, POINTSIZE, 72);
  172.     iPointSize *= -1;
  173.  
  174.     hFontCopyright = CreateFont(iPointSize,
  175.                                 0, 0, 0,
  176.                                 FW_BOLD,
  177.                                 0, 0, 0, 0,
  178.                                 0, 0, 0, 0,
  179.                                 "Arial");
  180.  
  181.     SendDlgItemMessage(hdlg, 
  182.                        IDD_VERLAST, 
  183.                        WM_SETFONT, 
  184.                        (WPARAM)hFontCopyright,
  185.                        0L);
  186.  
  187.     // Get version information from the application
  188.     GetModuleFileName(hInst, szFullPath, sizeof(szFullPath));
  189.     dwVerInfoSize = GetFileVersionInfoSize(szFullPath, &dwVerHnd);
  190.     if (dwVerInfoSize)
  191.     {
  192.         // If we were able to get the information, process it:
  193.         HANDLE  hMem;
  194.         LPVOID  lpvMem;
  195.         char    szGetName[256];
  196.         int     cchRoot;
  197.         int     i;
  198.  
  199.         hMem = GlobalAlloc(GMEM_MOVEABLE, dwVerInfoSize);
  200.         lpvMem = GlobalLock(hMem);
  201.         GetFileVersionInfo(szFullPath, dwVerHnd, dwVerInfoSize, lpvMem);
  202.         lstrcpy(szGetName, "\\StringFileInfo\\040904E4\\");
  203.         cchRoot = lstrlen(szGetName);
  204.  
  205.         // Walk through the dialog items that we want to replace:
  206.         for (i = IDD_VERFIRST; i <= IDD_VERLAST; i++)
  207.           {
  208.                 #pragma warn -sus
  209.                 BOOL  fRet;
  210.                 UINT  cchVer = 0;
  211.                 LPSTR lszVer = NULL;
  212.                 char  szResult[256];
  213.  
  214.                 GetDlgItemText(hdlg, i, szResult, sizeof(szResult));
  215.                 lstrcpy(&szGetName[cchRoot], szResult);
  216.                 fRet = VerQueryValue(lpvMem, szGetName, &lszVer, &cchVer);
  217.  
  218.                 if (fRet && cchVer && lszVer)
  219.                 {
  220.                      // Replace dialog item text with version info
  221.                      lstrcpy(szResult, lszVer);
  222.                      SetDlgItemText(hdlg, i, szResult);
  223.                 }
  224.                 #pragma warn .sus
  225.           }
  226.           GlobalUnlock(hMem);
  227.           GlobalFree(hMem);
  228.     }
  229.     return TRUE;
  230. }
  231.  
  232. //
  233. //  FUNCTION: MsgAboutCommand(HWND, UINT, WPARAM, LPARAM)
  234. //
  235. //  PURPOSE: Process WM_COMMAND message sent to the about box.
  236. //
  237. //  PARAMETERS:
  238. //    hwnd - The window handing the message.
  239. //    uMessage - The message number. (unused).
  240. //    wparam - Message specific data (unused).
  241. //    lparam - Message specific data (unused).
  242. //
  243. //  RETURN VALUE:
  244. //    Always returns 0 - message handled.
  245. //
  246. //  COMMENTS:
  247. //    Uses this DipsCommand function defined in wndproc.c combined
  248. //    with the cmdiAbout structure defined in this file to handle
  249. //    the command messages for the about dialog box.
  250. //
  251.  
  252. #pragma argsused
  253. LRESULT MsgAboutCommand(HWND   hwnd,
  254.                         UINT   uMessage, 
  255.                         WPARAM wparam, 
  256.                         LPARAM lparam)
  257. {
  258.     return DispCommand(&cmdiAbout, hwnd, wparam, lparam);
  259. }
  260.  
  261. //
  262. //  FUNCTION: CmdAboutDone(HWND, WORD, HWND)
  263. //
  264. //  PURPOSE: Free the about box and related data.
  265. //
  266. //  PARAMETERS:
  267. //    hwnd - The window handling the command.
  268. //    wCommand - The command to be handled (unused).
  269. //    wNotify   - Notification number (unused)
  270. //    hwndCtrl - NULL (unused).
  271. //
  272. //  RETURN VALUE:
  273. //    Always returns TRUE.
  274. //
  275. //  COMMENTS:
  276. //    Calls EndDialog to finish the dialog session.
  277. //
  278.  
  279. #pragma argsused
  280. LRESULT CmdAboutDone(HWND hdlg, WORD wCommand, WORD wNotify, HWND hwndCtrl)
  281. {
  282.     if (hFontCopyright)
  283.        DeleteObject(hFontCopyright);
  284.  
  285.     EndDialog(hdlg, TRUE);          // Exit the dialog
  286.     return TRUE;
  287. }
  288.